<?php

/**
 * ForumsDiscussion
 */
class ForumsDiscussion {

    /**
     * @var integer $id
     */
    private $id;
    /**
     * @var string $title
     */
    private $title;
    /**
     * @var text $content
     */
    private $content;
    /**
     * @var datetime $created_at
     */
    private $created_at;
    /**
     * @var Forum
     */
    private $forum;
    /**
     * @var User
     */
    private $user;
    /**
     * @var ForumsMessage
     */
    private $messages;


    /**
     * @var User
     */
    private $readers;

    public function __construct() {
        $this->messages = new \Doctrine\Common\Collections\ArrayCollection();
        $this->readers = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer $id
     */
    public function getId() {
        return $this->id;
    }

    /**
     * Set title
     *
     * @param string $title
     */
    public function setTitle($title) {
        $this->title = $title;
    }

    /**
     * Get title
     *
     * @return string $title
     */
    public function getTitle() {
        return $this->title;
    }

    /**
     * Set content
     *
     * @param text $content
     */
    public function setContent($content) {
        $this->content = $content;
    }

    /**
     * Get content
     *
     * @return text $content
     */
    public function getContent() {
        return $this->content;
    }

    /**
     * Set created_at
     *
     * @param datetime $createdAt
     */
    public function setCreatedAt($createdAt) {
        $this->created_at = $createdAt;
    }

    /**
     * Get created_at
     *
     * @return datetime $createdAt
     */
    public function getCreatedAt() {
        return $this->created_at;
    }

    /**
     * Set forum
     *
     * @param Forum $forum
     */
    public function setForum(\Forum $forum) {
        $this->forum = $forum;
    }

    /**
     * Get forum
     *
     * @return Forum $forum
     */
    public function getForum() {
        return $this->forum;
    }

    /**
     * Set user
     *
     * @param User $user
     */
    public function setUser(\User $user) {
        $this->user = $user;
    }

    /**
     * Get user
     *
     * @return User $user
     */
    public function getUser() {
        return $this->user;
    }

    /**
     * @var datetime $updated_at
     */
    private $updated_at;

    /**
     * Set updated_at
     *
     * @param datetime $updatedAt
     */
    public function setUpdatedAt($updatedAt) {
        $this->updated_at = $updatedAt;
    }

    /**
     * Get updated_at
     *
     * @return datetime $updatedAt
     */
    public function getUpdatedAt() {
        return $this->updated_at;
    }

    /**
     * Add messages
     *
     * @param ForumsMessage $messages
     */
    public function addMessages(\ForumsMessage $messages) {
        $this->messages[] = $messages;
    }

    /**
     * Get messages
     *
     * @return Doctrine\Common\Collections\Collection $messages
     */
    public function getMessages() {
        return $this->messages;
    }


    /**
     * Add readers
     *
     * @param User $readers
     */
    public function addReaders(\User $readers) {
        $this->readers[] = $readers;
    }

    /**
     * Get readers
     *
     * @return Doctrine\Common\Collections\Collection $readers
     */
    public function getReaders() {
        return $this->readers;
    }

    public function isRead($_session) {
        if (!$_session->isAuthenticated()) {
            return true;
        }

        foreach ($this->readers AS $reader) {
            if ($_session->getUser()->getId() == $reader->getId()) {
                return true;
            }
        }
        return false;
    }

    public function read($_session) {
        if (!$_session->isAuthenticated()) {
            return false;
        }

        foreach ($this->readers AS $reader) {
            if ($reader->getId() == $_session->getUser()->getId()) {
                return true;
            }
        }

        $this->readers[] = $_session->getUser();
    }

}